﻿using System;
using System.Collections.Generic;

namespace FDEE.Model
{
    public class BPTL1 : BPTMBase
    {

        public BPTL1(string typeName, string pierNumber,
            int height, double width, double lwidth,int calculatedHeight, int L1, int L2,
            int span) :
            base(typeName, pierNumber, height, width,lwidth, calculatedHeight,  L1, L2, span)
        {
        }


        public override void SetRebarList()
        {
            RebarList = new RebarCollection();
            #region 全局钢筋数量
            if (Width > 22000)
            {
                int N1 = 8; // 取决于L1,L2差是否是800
                int N2 =4; // CalculateHe==800;
                int N41 = 10;
                int N43 = 5;
                int N8 = 6 * 2;
                int N10 = 9;
                int N12 = 6;
                int N13 = 4;
                int N14 = 4 * 2;
                int N15 = 10 * 2;
                int N16 = 2;

                #endregion

                #region 1号钢筋
                double LEN1 = (Width - 2 * 50 - 12000) / 2 - 1000 + 1400;
                double LEN2 = 12000;
                double LEN3 = (Width - 2 * 50 - 12000) / 2 + 1000 + 1400;
                if (LEN1 > 12000 || LEN3 > 12000)
                {
                    throw new Exception("钢筋超过定尺");
                }
                RebarList.Add(new MARebarRecord(1, 1, "", eDB.DB25, (int)LEN1, N1, eShapeType.MA));
                RebarList.Add(new MARebarRecord(1, 2, "", eDB.DB25, (int)LEN2, N1, eShapeType.MA));
                RebarList.Add(new MARebarRecord(1, 3, "", eDB.DB25, (int)LEN3, N1, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB25] += 4 * N1 * 2;
                #endregion


                #region 2号钢筋
                LEN1 = (Width - 2 * 50 - 12000) / 2 - 1000 + 640;
                LEN2 = 12000;
                LEN3 = (Width - 2 * 50 - 12000) / 2 + 1000 + 640;
                if (LEN1 > 12000 || LEN3 > 12000)
                {
                    throw new Exception("钢筋超过定尺");
                }
                RebarList.Add(new MARebarRecord(2, 1, "", eDB.DB16, (int)LEN1, N2, eShapeType.MA));
                RebarList.Add(new MARebarRecord(2, 2, "", eDB.DB16, (int)LEN2, N2, eShapeType.MA));
                RebarList.Add(new MARebarRecord(2, 3, "", eDB.DB16, (int)LEN3, N2, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB16] += 3 * N2 * 2;
                #endregion

                #region 4#
                int C = (int)Math.Round((Width - 100 - 12000) / 2 - 1000 + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 1, "", eDB.DB28, N41, eShapeType.MU, 500, 900 - 100 - 16 - 28, C, 200 - 50 - 25 - 16, 75));
                C = (int)Math.Round((Width - 100 - 12000) / 2 + 1000 + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 2, "", eDB.DB28, N41, eShapeType.MU, 500, 900 - 100 - 16 - 28, C, 200 - 50 - 25 - 16, 75));
                C = (int)Math.Round((Width - 100 - 12000) / 2 - 1000 + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 3, "", eDB.DB28, N43, eShapeType.MUC, 500, 290 - 50 - 60, C, 200 - 50 - 25 - 16, 0));
                C = (int)Math.Round((Width - 100 - 12000) / 2 + 1000 + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 4, "", eDB.DB25, N43, eShapeType.MUC, 500, 290 - 50 - 60, C, 200 - 50 - 25 - 16, 0));
                RebarList.Add(new MARebarRecord(4, 5, "", eDB.DB28, 12000, N41 + N43, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB28] += 3 * (N41 + N43) * 2;
                #endregion

                #region 5# 6# 7# 
                var AA = CalculatedHeight - 2 * 50 - 16 - 25;
                var BB = L1 - 2 * 50 - 2 * 16;
                int quan = (int)Math.Round(Width / 150, MidpointRounding.AwayFromZero) + 1;
                RebarList.Add(new MCRebarRecord(5, 0, "", eDB.DB25, AA, BB, AA, quan, eShapeType.MCB));
                AA = CalculatedHeight - 2 * 50 - 25 - 25;
                RebarList.Add(new MCRebarRecord(6, 0, "", eDB.DB16, AA, BB, AA, quan, eShapeType.MCB));
                //quan = (int)Math.Round(Width / 300, MidpointRounding.AwayFromZero) + 1;
                quan = (int)(Math.Round(Width / 600, MidpointRounding.AwayFromZero) + 1) * 3;
                RebarList.Add(new MORebarRecord(7, 0, "", eDB.DB16, quan, eShapeType.MO, L1 - 2 * 50 - 2 * 16, 350));

                #endregion

                #region 8#
                LEN1 = (Width - 2 * 50 - 12000) / 2 - 1000 + 640;
                LEN2 = 12000;
                LEN3 = (Width - 2 * 50 - 12000) / 2 + 1000 + 640;
                if (LEN1 > 12000 || LEN3 > 12000)
                {
                    throw new Exception("钢筋超过定尺");
                }
                RebarList.Add(new MARebarRecord(8, 1, "", eDB.DB16, (int)LEN1, N8, eShapeType.MA));
                RebarList.Add(new MARebarRecord(8, 2, "", eDB.DB16, (int)LEN2, N8, eShapeType.MA));
                RebarList.Add(new MARebarRecord(8, 3, "", eDB.DB16, (int)LEN3, N8, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB16] += 3 * N8 * 2;
                #endregion

                #region 9#
                var LSide = 5300;// 两侧加密长度

                quan = (int)Math.Round((Width - 100) / 100, MidpointRounding.AwayFromZero);
                AA = Height - 2 * 50 - 2 * 16;
                BB = L2 - 2 * 50 - 2 * 16;
                RebarList.Add(new MORebarRecord(9, 1, "", eDB.DB16, quan, eShapeType.MO, AA, BB));
                //RebarList.Add(new MORebarRecord(9, 2, "", eDB.DB16, quan, eShapeType.MO90, AA, 2 * 270 + 120));
                RebarList.Add(new MORebarRecord(9, 2, "", eDB.DB16, quan, eShapeType.MO, AA, 65 * 4 + 32));
                #endregion

                #region 10#
                LEN1 = (Width - 2 * 50 - 12000) / 2 - 1000 + 1400;
                LEN3 = 12000;
                LEN2 = (Width - 2 * 50 - 12000) / 2 + 1000 + 1400;

                RebarList.Add(new MARebarRecord(10, 1, "", eDB.DB32, (int)LEN1, N10, eShapeType.MA));
                RebarList.Add(new MARebarRecord(10, 2, "", eDB.DB32, (int)LEN2, N10, eShapeType.MA));
                RebarList.Add(new MARebarRecord(10, 3, "", eDB.DB32, (int)LEN3, N10 * 2, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB25] += 5 * (N10) * 2;
                #endregion

                #region 12#-17#

                int BlockThick = 200;

                AA = 1500 - 50;
                BB = 2 * 207 + 120 + 2 * 25 + 2 * 12;
                //BB = 294;
                RebarList.Add(new MCRebarRecord(12, 0, "", eDB.DB12, AA, BB, AA, N12, eShapeType.MCB));
                RebarList.Add(new MURebarRecord(13, 0, "", eDB.DB25, N13, eShapeType.MUR, 1450, Height - 100, 1450, 109, 75));
                AA = Height - 2 * 50;
                BB = BlockThick - 2 * 50 - 2 * 12;
                RebarList.Add(new MCRebarRecord(14, 0, "", eDB.DB12, AA, BB, AA, N14, eShapeType.MCB));
                AA = BlockThick - 2 * 50 - 2 * 12;
                BB = (int)Math.Round((L1 - L2) * 0.5 - 2 * 50 - 2 * 12, MidpointRounding.AwayFromZero);
                RebarList.Add(new MORebarRecord(15, 0, "", eDB.DB12, N15, eShapeType.MO, AA, BB));
                //AA = Height - 100 - 2 * 12;
                //BB = 1200 - 2 * 50 - 2 * 12;
                //RebarList.Add(new MORebarRecord(16, 0, "", eDB.DB12, N16, eShapeType.MO, AA, BB));
                //RebarList.Add(new MORebarRecord(17, 0, "", eDB.DB12, N17, eShapeType.MO, AA, BB));
                #endregion

                #region 16#
                AA = 1500 - 50;
                BB = L1 - 2 * 50;
                RebarList.Add(new MCRebarRecord(16, 0, "", eDB.DB12, AA, BB, AA, N16, eShapeType.MCB));


                #endregion
            }
            else
            {
                int N1 = 8; // 取决于L1,L2差是否是800
                int N2 =4; // CalculateHe==800;
                int N31 = 15;
                int N32= 10;
                int N41 = 10;
                int N43 = 5;
                int N8 = 6 * 2;
                int N10 = 9;
                int N12 = 6*2;
                int N13 = 4*2;
                int N14 = 4 * 2*2;
                int N15 = 7 * 2*2;
                int N16 = 2*2;

                #region 1号钢筋
                double LEN1 = (Width - 2 * 50 - 12000) + 1400;
                double LEN2 = 12000;
                //double LEN3 = (Width - 2 * 50 - 12000) / 2 + 1000 + 1400;
                if (LEN1 > 12000 )
                {
                    throw new Exception("钢筋超过定尺");
                }
                RebarList.Add(new MARebarRecord(1, 1, "", eDB.DB25, (int)LEN1, N1, eShapeType.MA));
                RebarList.Add(new MARebarRecord(1, 2, "", eDB.DB25, (int)LEN2, N1, eShapeType.MA));
                //RebarList.Add(new MARebarRecord(1, 3, "", eDB.DB25, (int)LEN3, N1, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB25] += 2 * N1 * 2;
                #endregion


                #region 2号钢筋
                LEN1 = (Width - 2 * 50 - 12000)+ 640;
                LEN2 = 12000;
                //LEN3 = (Width - 2 * 50 - 12000) / 2 + 1000 + 640;
                if (LEN1 > 12000 )
                {
                    throw new Exception("钢筋超过定尺");
                }
                RebarList.Add(new MARebarRecord(2, 1, "", eDB.DB16, (int)LEN1, N2, eShapeType.MA));
                RebarList.Add(new MARebarRecord(2, 2, "", eDB.DB16, (int)LEN2, N2, eShapeType.MA));
                //RebarList.Add(new MARebarRecord(2, 3, "", eDB.DB16, (int)LEN3, N2, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB16] += 2 * N2 * 2;
                #endregion

                #region 3#
                //int C = (int)Math.Round((Width - 100 - 12000) + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MARebarRecord(3, 1, "", eDB.DB28, (int)Width - 2700 * 2 - 2000 * 2, N31, eShapeType.MA));
                RebarList.Add(new MARebarRecord(3, 2, "", eDB.DB28, (int)Width - 2700 * 2 - 2000 * 2 - 1500 * 2,  N32, eShapeType.MA));
                //UboltList.UBoltNum[eDB.DB28] +=  (N31 + N32) * 2;
                #endregion

                #region 4#
                int C = (int)Math.Round((Width - 100 - 12000)  + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 1, "", eDB.DB28, N41, eShapeType.MU, 500, 900 - 100 - 16 - 28, C, 200 - 50 - 25 - 16, 75));
                //C = (int)Math.Round((Width - 100 - 12000) / 2 + 1000 + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 2, "", eDB.DB28, N41, eShapeType.MU, 500, 900 - 100 - 16 - 28, C, 200 - 50 - 25 - 16, 75));
                C = (int)Math.Round((Width - 100 - 12000)  + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 3, "", eDB.DB28, N43, eShapeType.MUC, 500, 290 - 50 - 60, C, 200 - 50 - 25 - 16, 0));
                //C = (int)Math.Round((Width - 100 - 12000) / 2 + 1000 + 980, MidpointRounding.AwayFromZero);
                RebarList.Add(new MURebarRecord(4, 4, "", eDB.DB28, N43, eShapeType.MUC, 500, 290 - 50 - 60, C, 200 - 50 - 25 - 16, 0));

                UboltList.UBoltNum[eDB.DB28] += 2 * (N41 + N43) * 2;
                #endregion

                #region 5# 6# 7# 
                var AA = CalculatedHeight - 2 * 50 - 16 - 25;
                var BB = L1 - 2 * 50 - 2 * 16;
                int quan = (int)Math.Round(Width / 200, MidpointRounding.AwayFromZero) + 1;
                RebarList.Add(new MCRebarRecord(5, 0, "", eDB.DB25, AA, BB, AA, quan, eShapeType.MCB));
                AA = CalculatedHeight - 2 * 50 - 25 - 25;
                RebarList.Add(new MCRebarRecord(6, 0, "", eDB.DB16, AA, BB, AA, quan, eShapeType.MCB));
                //quan = (int)Math.Round(Width / 300, MidpointRounding.AwayFromZero) + 1;
                quan = (int)(Math.Round((Width / 550 ), MidpointRounding.AwayFromZero) + 1) * 2;
                RebarList.Add(new MORebarRecord(7, 0, "", eDB.DB16, quan, eShapeType.MO, L1 - 2 * 50 - 2 * 16, 400));

                #endregion

                #region 8#
                LEN1 = (Width - 2 * 50 - 12000)  + 640;
                LEN2 = 12000;
                //LEN3 = (Width - 2 * 50 - 12000) / 2 + 1000 + 640;
                if (LEN1 > 12000 )
                {
                    throw new Exception("钢筋超过定尺");
                }
                RebarList.Add(new MARebarRecord(8, 1, "", eDB.DB16, (int)LEN1, N8, eShapeType.MA));
                RebarList.Add(new MARebarRecord(8, 2, "", eDB.DB16, (int)LEN2, N8, eShapeType.MA));
                //RebarList.Add(new MARebarRecord(8, 3, "", eDB.DB16, (int)LEN3, N8, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB16] += 2 * N8 * 2;
                #endregion

                #region 9#
                var LSide = 5300;// 两侧加密长度

                quan = (int)Math.Round((Width - 100) / 200, MidpointRounding.AwayFromZero);
                quan = 27*2+30*2+9;
                AA = Height - 2 * 50 - 2 * 16;
                BB = L2 - 2 * 50 - 2 * 16;
                RebarList.Add(new MORebarRecord(9, 1, "", eDB.DB16, quan, eShapeType.MO, AA, BB));
                //RebarList.Add(new MORebarRecord(9, 2, "", eDB.DB16, quan, eShapeType.MO90, AA, 2 * 270 + 120));
                RebarList.Add(new MORebarRecord(9, 2, "", eDB.DB16, quan, eShapeType.MO, AA, 65 * 4 + 32));
                #endregion

                #region 10#
                LEN1 = (Width - 2 * 50 - 12000) + 1400;
                LEN2 = 12000;
                //LEN2 = (Width - 2 * 50 - 12000) / 2 + 1000 + 1400;

                RebarList.Add(new MARebarRecord(10, 1, "", eDB.DB32, (int)LEN1, N10, eShapeType.MA));
                RebarList.Add(new MARebarRecord(10, 2, "", eDB.DB32, (int)LEN2, N10, eShapeType.MA));
                RebarList.Add(new MARebarRecord(10, 3, "", eDB.DB32, (int)LEN1+2500, N10 * 2, eShapeType.MA));
                UboltList.UBoltNum[eDB.DB32] += 2 * (N10) * 2;
                #endregion

                #region 12#-17#

                int BlockThick = 200;

                AA = 1500 - 50;
                BB = 2 * 207 + 120 + 2 * 25 + 2 * 12;
                //BB = 294;
                RebarList.Add(new MCRebarRecord(12, 0, "", eDB.DB12, AA, BB, AA, N12, eShapeType.MCB));
                RebarList.Add(new MURebarRecord(13, 0, "", eDB.DB25, N13, eShapeType.MUR, 1450, Height - 100, 1450, 109, 75));
                AA = Height - 2 * 50;
                BB = BlockThick - 2 * 50 - 2 * 12;
                RebarList.Add(new MCRebarRecord(14, 0, "", eDB.DB12, AA, BB, AA, N14, eShapeType.MCB));
                AA = BlockThick - 2 * 50 - 2 * 12;
                BB = (int)Math.Round((L1 - L2) * 0.5 - 2 * 50 - 2 * 12, MidpointRounding.AwayFromZero);
                RebarList.Add(new MORebarRecord(15, 0, "", eDB.DB12, N15, eShapeType.MO, AA, BB));
       
                #endregion

                #region 16#
                AA = 1500 - 50;
                BB = L1 - 2 * 50;
                RebarList.Add(new MCRebarRecord(16, 0, "", eDB.DB12, AA, BB, AA, N16, eShapeType.MCB));


                #endregion
            }

        }

        public override void SetTendonList(ref System.Data.DataTable ElongTable)
        {
            TendonDistribute = new RebarTendonDistribute(320, new List<double>() { });
        }
    }

}
